package com.beiding.v2.grammar;

import com.beiding.v2.element.IField;
import com.beiding.v2.element.IFiledCapture;
import com.beiding.v2.element.ITable;
import com.beiding.v2.type.FunctionType;

public class FieldCapture implements IFiledCapture {

    private IField field;


    private FunctionType functionType;

    private String as;


    public FieldCapture(IField field) {
        this.field = field;
    }

    public FieldCapture (ITable table, String name) {
        F f = new F();
        f.table = table;
        f.name = name;
        this.field = f;
    }

    public FieldCapture count() {
        return function(FunctionType.count);
    }

    public FieldCapture function(FunctionType functionType) {
        this.functionType = functionType;
        return this;
    }

    public FieldCapture as(String as) {
        this.as = as;
        return this;
    }

    @Override
    public IField getField() {
        return field;
    }

    @Override
    public FunctionType getFunctionType() {
        return functionType;
    }


    @Override
    public String getAs() {
        return as;
    }

    private static class F implements IField {

        ITable table;

        String name;

        @Override
        public ITable getTable() {
            return this.table;
        }

        @Override
        public String getName() {
            return name;
        }
    }


}
